package ph.gov.marikina.mcsmtms.tests;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.List;

import org.junit.Assert;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import ph.gov.marikina.mcsmtms.constants.GlobalConstants.UserTypes;
import ph.gov.marikina.mcsmtms.dao.UserDAO;
import ph.gov.marikina.mcsmtms.domain.User;
import ph.gov.marikina.mcsmtms.domain.UserType;

public class UserDAOTest {
	/** The context. */
	private static ApplicationContext springContext = new ClassPathXmlApplicationContext(
			"spring/test-spring-config.xml");
	
	@Test
	public void testAddUser() {
		//fail("Not yet implemented");
		UserDAO userDAO = (UserDAO) springContext
				.getBean("userDAO");
		
		User newUser = new User();
		
		newUser.setFullName("Juan Dela Cruz");
		newUser.setUserName("juan");
		newUser.setPassword("1");
		newUser.setUserType(UserTypes.USER.getCode());
		newUser.setHasMobileAlert(true);
		newUser.setMobileNumber("09178994386");
		
		userDAO.addUser(newUser);
		
		User findUser = userDAO.getUser("juan");
		Assert.assertNotNull(findUser);
		Assert.assertEquals(newUser.getFullName(), findUser.getFullName());
	}
	
	@Test
	public void getAlertUsers() {
		UserDAO userDAO = (UserDAO) springContext
				.getBean("userDAO");
		
		List<User> alertUserList = userDAO.getAlertUsers();
		
		assertNotNull(alertUserList);
		assertTrue(alertUserList.size() > 0);
	}
}
